package com.ruoyi.good.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.good.domain.vo.GoodVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.good.domain.TestGood;
import com.ruoyi.good.service.ITestGoodService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 管理商品Controller
 * 
 * @author 程序员dd
 * @date 2025-09-03
 */
@RestController
@RequestMapping("/good/good")
public class TestGoodController extends BaseController
{
    @Autowired
    private ITestGoodService testGoodService;

    /**
     * 查询管理商品列表
     */
    @PreAuthorize("@ss.hasPermi('good:good:list')")
    @GetMapping("/list")
    public TableDataInfo list(TestGood testGood)
    {
//        startPage();
//        List<TestGood> list = testGoodService.selectTestGoodList(testGood);
//        return getDataTable(list);
        startPage();
        List<GoodVo> list = testGoodService.getTypeNameByGoodList(testGood);
        return getDataTable(list);
    }

    /**
     * 导出管理商品列表
     */
    @PreAuthorize("@ss.hasPermi('good:good:export')")
    @Log(title = "管理商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TestGood testGood)
    {
        List<TestGood> list = testGoodService.selectTestGoodList(testGood);
        ExcelUtil<TestGood> util = new ExcelUtil<TestGood>(TestGood.class);
        util.exportExcel(response, list, "管理商品数据");
    }

    /**
     * 获取管理商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('good:good:query')")
    @GetMapping(value = "/{goodId}")
    public AjaxResult getInfo(@PathVariable("goodId") Long goodId)
    {
        return success(testGoodService.selectTestGoodByGoodId(goodId));
    }

    /**
     * 新增管理商品
     */
    @PreAuthorize("@ss.hasPermi('good:good:add')")
    @Log(title = "管理商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TestGood testGood)
    {
        return toAjax(testGoodService.insertTestGood(testGood));
    }

    /**
     * 修改管理商品
     */
    @PreAuthorize("@ss.hasPermi('good:good:edit')")
    @Log(title = "管理商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TestGood testGood)
    {
        return toAjax(testGoodService.updateTestGood(testGood));
    }

    /**
     * 删除管理商品
     */
    @PreAuthorize("@ss.hasPermi('good:good:remove')")
    @Log(title = "管理商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodIds}")
    public AjaxResult remove(@PathVariable Long[] goodIds)
    {
        return toAjax(testGoodService.deleteTestGoodByGoodIds(goodIds));
    }
}
